import java.io.UnsupportedEncodingException;


public class CrcTest {
	public static int calccrc(int crcbuf, int crc) {
		int i;
		int chk;

		crc = crc ^ crcbuf;

		for (i = 0; i < 8; i++) {
			chk = (int) (crc & 1);
			crc = crc >> 1;
			crc = crc & 0x7fff;
			if (chk == 1) {
				crc = crc ^ 0xa001;
			}
			crc = crc & 0xffff;
		}

		return crc;
	}

	public static int chkcrc(int buf[], int len) {
		int hi, lo;
		int i;
		int crc;

		crc = 0xFFFF;

		for (i = 0; i < len; i++) {
			crc = calccrc(buf[i], crc);
		}

		lo = (int) (crc % 256);
		hi = (int) (crc / 256);
		crc = (hi << 8) | lo;

		return crc;
	}


	
	

	public static void main(String[] args) {
		 System.out.println(chkcrc(new int[]{85,170,16,0,0,0, 0,0, 0,0,0,0},12));
		 

//		 System.out.println(Integer.toHexString(chkcrc(tointArray(null),tointArray(null).length)));

		// int[] number = {0x01,
		// 0x31,0x35,0x39,0x38,0x32,0x38,0x36,0x39,0x35,0x37};
		//
		// for(int i:number){
		//
		// System.out.println(i);
		//
		// }



	}
}
